﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Cormant.Mvc.Web
{
    [HtmlTag("tr")]
    public class MvcTableRow : MvcControl
    {
        #region MvcTableRow : Constructors.
        public MvcTableRow(HtmlHelper html)
            : base(html, string.Empty)
        {
            this.Cells = new List<MvcTableCell>();
        }

        public MvcTableRow(HtmlHelper html, string id)
            : base(html, id)
        {
            this.Cells = new List<MvcTableCell>();
        }
        #endregion

        #region MvcTableRow : Properties.
        public IList<MvcTableCell> Cells { get; set; }
        #endregion

        #region MvcTableRow : Methods.
        public override string ToString()
        {
            StringBuilder markup = new StringBuilder();
            markup.AppendLine(base.ToString(TagRenderMode.StartTag));
            if (this.Cells != null && this.Cells.Count > 0)
            {
                foreach (MvcTableCell cell in this.Cells)
                {
                    if (cell != null)
                        markup.AppendLine(cell.ToString());
                }
            }
            markup.AppendLine(base.ToString(TagRenderMode.EndTag));

            return markup.ToString();
        }
        #endregion
    }
}
